using MediatR;
using SHOLF.Library;

namespace ChikovMF.Application.Features.SHOLF;

public class SHOLFCommandHandler : IRequestHandler<SHOLFCommand, ICollection<string>>
{
    public async Task<ICollection<string>> Handle(SHOLFCommand request, CancellationToken cancellationToken)
    {
        _hasher.Notify += request.ProgressShow;

        var result = await _hasher.GetHashAsync(request.File.OpenReadStream(), request.HashAlgorithm, request.SegmentCount);

        return result;
    }

    private readonly IHasher _hasher;

    public SHOLFCommandHandler(IHasher hasher)
    {
        _hasher = hasher;
    }
}
